package com.ryskoo.catering.orderdetail.repository;

import com.ryskoo.catering.orderdetail.domain.OrderDetailPO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import com.ryskoo.framework.core.utils.ReflectHelper;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class OrderDetailJPAImpl extends BasicJPAImpl<OrderDetailPO> implements IOrderDetailRepository {
    @Override
    public List<OrderDetailPO> getDetailListByOrderUuid(String orderUuid) {
        String hql = "select o" + getMultiSelect() + " from "
                + ReflectHelper.getModelClass(this.getClass()).getName()
                + " o " + getMultiModel() + " where orderUuid=:orderUuid ";

        Query q = getH4Session().createQuery(hql);
        q.setString("orderUuid", orderUuid);

        return q.list();
    }

    @Override
    public List<String> getUuidsByProductUuid(String productUuid) {
        String hql = "select o.uuid from OrderDetailPO o where o.productUuid=:productUuid ";
        Query q = getH4Session().createQuery(hql);
        q.setString("productUuid", productUuid);
        return q.list();
    }

    @Override
    public List<String> getDetailUuidsByOrderUuid(String orderUuid) {
        String hql = "select o.uuid from OrderDetailPO o where o.orderUuid = :orderUuid ";
        Query q = getH4Session().createQuery(hql);
        q.setString("orderUuid", orderUuid);
        return q.list();
    }
}
